package com.sinaapp.gavinzhang.GSpider.examples;

import com.sinaapp.gavinzhang.GSpider.Exception.GSpiderInitException;
import com.sinaapp.gavinzhang.GSpider.GSpider;
import com.sinaapp.gavinzhang.GSpider.GSpiderBuilder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.regex.Pattern;

/**
 * Created by gavin on 15-8-2.
 */
public class Zhilianzhaopin {
    //http://sou.zhaopin.com/jobs/search?client=navclient-auto&hl=en&ch=62310169450&ie=UTF-8&oe=UTF-8&features=Rank&q=info
    public void test()throws Exception
    {
        Document html = Jsoup.connect("http://sou.zhaopin.com/jobs/searchresult.ashx?in=180000&sm=0&p=1").get();
        Elements table = html.select(".newlist").select("table");
        Elements job = table.select("tr");
        for (Element e : job)
        {
            System.out.println(e.text());
        }
    }

    public static void urls() throws GSpiderInitException {

        GSpiderBuilder builder = new GSpiderBuilder();
        builder.setPageProcessor(new ZhilianzhaopinPageProcessor());
        builder.addRegex(Pattern.compile("http://sou.zhaopin.com/jobs/searchresult.ashx.*[^#]"));
        builder.addWebUrl("http://sou.zhaopin.com/jobs/searchresult.ashx?in=180000&sm=0&p=" + 1);
        GSpider gSpider = builder.build();
        gSpider.controlInit();
    }

    public static void main(String[] args)throws Exception
    {
        //PropertyConfigurator.configure("classes/log4j.properties");
        urls();

    }

}
